package com.base.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.lazyzhao.util.pagination.Pagination;

public class ConstantService  extends BasicService{

	
	private final static String Table_Name="T_CONSTANT";
	
	
	private final static String SELECT_TABLE_NAME="";
	
	public int update(Connection conn,Map<String,Object> objects,String...wheres) throws SQLException{
		return query.update(conn, tname(Table_Name), objects,wheres);
	}
	public int insert(Connection conn,Map<String,Object> objects) throws SQLException{
		return query.insert(conn, tname(Table_Name), objects);
	}
	
	public Map<String,Object> findConstantMap(Connection conn,Map<String,Object> params,HttpServletRequest req)throws SQLException{
		String appId = String.valueOf(req.getSession().getAttribute("appId"));
		
		String sql = "(select b.*,a.name from  apps a , T_CONSTANT  b  where  a.id = b.app_name and a.id='"+appId+"') Z";
		
		return queryMap(conn, sql, params);
	}
	public Pagination<List<Map<String,Object>>> findConstant(Connection conn,Map<String,Object> params,Pagination<List<Map<String,Object>>> pagination,HttpServletRequest  req ) throws SQLException{
		String appId = String.valueOf(req.getSession().getAttribute("appId"));
		String sql = "(select b.*,a.name from  apps a , T_CONSTANT  b  where  a.id = b.app_name and a.id='"+appId+"') Z";
		return query(conn, sql, params, pagination);
	}

	public int deleteConstant(Connection conn,String[] ids) throws SQLException{
		Object[][] objs = new Object[ids.length][];
		for(int i=0;i<ids.length;i++){
			objs[i] = new Object[]{ids[i]}; 
		}
		int[] ints = query.batch(conn, "delete from " + tname(Table_Name) + " where id=?",objs);
		int count = 0;
		for(int i : ints){
			count+=i;
		}
		return count;
	}
}
